package Example_practice02;
class Point{
    double x;
    double y;
    public Point(double x,double y){
        this.x=x;
        this.y=y;
    }
    //计算两点之间的距离
    public double getDistance(Point point){
        double dx=Math.abs(x-point.x);
        double dy=Math.abs(x-point.y);
        return Math.sqrt(dx*dx+dy*dy);
    }
}
public class BFClosestPair {
    //计算最接近点对
    public static double closestPair(Point[] points){
        int n=points.length;
        double minDistance=Double.POSITIVE_INFINITY;//设置位无穷大
        for (int i=0;i<n;i++){
            for (int j=i+1;j<n;j++){
                double curDistance=points[i].getDistance(points[j]);
                minDistance=Math.min(curDistance,minDistance);
            }
        }
        return minDistance;
    }
    public static void main(String[] args){
        Point[] points={new Point(0,0),
                new Point(1,1),
                new Point(2,2),
                new Point(2,4),
        };
        double minDistance=closestPair(points);
        System.out.printf("最接近的距离为：%.4f",minDistance);
    }
}

